import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from cycler import cycler

mpl.rcParams['lines.linewidth'] = 2
mpl.rcParams['lines.linestyle'] = '--'
data = np.random.randn(50)
plt.plot(data)
plt.show()

mpl.rcParams['axes.prop_cycle'] = cycler(color=['r', 'g', 'b', 'y'])
plt.plot(data)  # first color is red
plt.show()

mpl.rc('lines', linewidth=4, linestyle='-.')
plt.plot(data)
plt.show()

with mpl.rc_context({'lines.linewidth': 2, 'lines.linestyle': ':'}):
    plt.plot(data)
    plt.show()

@mpl.rc_context({'lines.linewidth': 3, 'lines.linestyle': '-'})
def plotting_function():
    plt.plot(data)
    plt.show()
plotting_function()

print(plt.style.available)
plt.style.use('ggplot')

# 自定义风格
# plt.style.use('style/presentation.mplstyle')

with plt.style.context('dark_background'):
    plt.plot(np.sin(np.linspace(0, 2 * np.pi)), 'r-o')
plt.show()

# 显示当前活动matplotlibrc文件的加载位置
mpl.matplotlib_fname()